// pages/user/accumulatedIncomeHistory/accumulatedIncomeHistory.js
const common = require('../../../utils/util.js')
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inComeType: null,
    recordList: [],
    nowPage: 0,
    isLoading: false,
    isAll: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      inComeType: options.type
    })
    this.getRecordList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.getRecordList()
  },

  getRecordList: function() {
    if (this.data.isLoading) {
      return
    }
    if (this.data.isAll) {
      return
    }
    const that = this
    let data
    let recordList = this.data.recordList
    if (this.data.inComeType == 'all') {
      data = {
        type: 1,
        limit: 10,
        page: this.data.nowPage
      }
    } else if (this.data.inComeType == 'wait') {
      data = {
        type: 3,
        limit: 10,
        page: this.data.nowPage
      }
    } else {
      return
    }
    this.setData({
      isLoading: true
    })
    wx.showLoading({
      title: '加载中',
    })
    common.post('Wallet/user_money_old', data).then(function(res) {
      wx.hideLoading()
      that.setData({
        isLoading: false
      })
      if (res.code == 204) {
        that.setData({
          recordList: recordList,
          isAll: true
        })
      } else {
        recordList = recordList.concat(res)
        that.setData({
          recordList: recordList,
          nowPage: that.data.nowPage + 1
        })
      }
    }).catch(function(e) {})
  }
})